home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
STRINGS.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
2KB
|
84 lines
############################################################################
#
# File: strings.icn
#
# Subject: Procedures for string utilities
#
# Author: Ralph E. Griswold
#
# Date: May 26, 1989
#
###########################################################################
#
# These procedures perform simple operations on strings.
#
# compress(s,c) Compress consecutive occurrences of charac-
# ters in c that occur in s.
#
# omit(s,c) Omit all occurrences of characters in c
# that occur in s.
#
# replace(s1,s2,s3) In s1, replace all occurrences of s2 by s3.
#
# rotate(s,i) Rotate s i characters to the left (negative i
# produces rotation to the right); the default
# value of i is 1.
#
############################################################################
procedure compress(s,c)
local result, s1
result := ""
s ? {
while result ||:= tab(upto(c)) do {
result ||:= (s1 := move(1))
tab(many(s1))
}
return result || tab(0)
}
end
# omit characters
#
procedure omit(s,c)
local result, s1
result := ""
s ? {
while result ||:= tab(upto(c)) do {
s1 := move(1)
tab(many(s1))
}
return result || tab(0)
}
end
# replace string
#
procedure replace(s1,s2,s3)
local result, i
result := ""
i := *s2
s1 ? {
while result ||:= tab(find(s2)) do {
result ||:= s3
move(i)
}
return result || tab(0)
}
end
# rotate string
#
procedure rotate(s,i)
/i := 1
if i <= 0 then i +:= *s
i %:= *s
return s[i + 1:0] || s[1:i + 1]
end